function sim = sim_data_function(param,fp)
  
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%;
%Solving the model (Baseline or Counterfactual);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%;
%Baseline Economy (fp.do_counter==0);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%;
if fp.do_counter==0
        
    sim_data         = cell(4,1);
    sim_data_network = cell(4,1);

    Value0 = cell(4,1);
    Value1 = cell(4,1);
    
for j = 1:4 %Loop over different neighborhooods;
    
    %Solve the model;
    s = solve(j,fp,param);
    %Store simulated data;
    sim_data{j} = s.sim_data ; 
    sim_data_network{j} = s.sim_data_network;        
    Value0{j} = s.Value0;
    Value1{j} = s.Value1;
    
end

    sim.sim_data          = sim_data;
    sim.sim_data_network  = sim_data_network;       
    sim.Value0            = Value0;
    sim.Value1            = Value1;          
    
else %counterfactual


    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%;
    %fp.do_counter_type < 4 (Figures 3-6)
    %Simulate Policy #1: Moving one child;
    %Simulate Policy #2: Moving many children;
    %Simulate Policy #3: Moving many children (fixed parental behavior);
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%;

    if fp.do_counter_type < 4 
    
    s_c = solve_counter(fp,param);
    sim_data_counter = s_c.sim_data;
    sim_data_network_counter = s_c.sim_data_network;
    id_moved_children        = s_c.id_moved_children;        
    
    sim.sim_data          = sim_data_counter;
    sim.sim_data_network  = sim_data_network_counter;    
    sim.id_moved_children = id_moved_children;
        
    else % fp.do_counter_type>=4 for the rest of the policy analysis

    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%;
    %fp.do_counter_type>=4 for the rest of the policy analysis (Table 8)
    
    % fp.do_counter_type==4: No Inequality(all neighborhoods share initial aggregate mean)
    % fp.do_counter_type==5: No Between-Neighb. Inequality (all initial conditions = aggreg mean and SD)
    % fp.do_counter_type==6: No Within-Neighb. Inequality 
    % fp.do_counter_type==7: Truncate Local Distrib. at 10th percent (truncating within each neighborhod)
    % fp.do_counter_type==8: Halving Cost of Parental Investments
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%;

                
    sim_data         = cell(4,1);
    sim_data_network = cell(4,1);
    
    for j = 1:4 %Loop over different neighborhooods;
        %Solve the model;
        s = solve(j,fp,param);
        %Store simulated data;
        sim_data{j} = s.sim_data ; 
        sim_data_network{j} = s.sim_data_network;    
    end

    sim.sim_data          = sim_data;        
    sim.sim_data_network  = sim_data_network;          
        
    end
        
end

